import { http } from "@/utils/http";

/** 集群服务器模型定义 */
export type ClusterServerModel = {
  id: number;
  name: string;
  serverKey: string;
  dataDiskPath: string;
  status: number;
  remark: string;
  createdAt: string;
  updatedAt: string;
};

/** 分页获取集群服务器列表 */
export const getClusterServerListApi = (data: IReqPagerData) => {
  return http.request<Resp<IRespPagerData<ClusterServerModel>>>(
    "get",
    "/cluster/server/page-list",
    { params: data }
  );
};

/** 新增集群服务器 */
export const addClusterServerApi = (data: Partial<ClusterServerModel>) => {
  return http.request<Resp<null>>("post", "/cluster/server", { data });
};

/** 更新集群服务器 */
export const updateClusterServerApi = (id: number, data: Partial<ClusterServerModel>) => {
  return http.request<Resp<null>>("put", `/cluster/server/${id}`, { data });
};

/** 删除集群服务器 */
export const deleteClusterServerApi = (id: number) => {
  return http.request<Resp<null>>("delete", `/cluster/server/${id}`);
};

/** 根据ID获取集群服务器详情 */
export const getClusterServerByIdApi = (id: number) => {
  return http.request<Resp<ClusterServerModel>>('get', '/cluster/server/getOne', {
    params: { id }
  });
};

/** 获取集群服务器选项列表 */
export const getClusterServerOptionsApi = (params?: { fieldKey?: string; fieldLabel?: string }) => {
  return http.request<Resp<{
    options: Array<{
      label: string;
      val: string | number;
    }>
  }>>('get', '/cluster/server/getOptions', { params });
};

/** 获取集群服务器标识列表 */
export const getClusterServerKeysApi = (type: string) => {
  return http.request<Resp<{
    options: Array<{
      label: string;
      val: string;
    }>
  }>>('get', '/cluster/server/getClusterKeys', {
    params: { type }
  });
};